#!/usr/bin/env python
# -*- coding: utf-8 -*-

""" Collect User ID from Cisco internal DIR page
"""

import sys
import urllib
from HTMLParser import HTMLParser
import random

URL = "http://wwwin-tools.cisco.com/dir/details/"

"""
"""

class EmployeeInfo(object):
    def __init__(self, info={}):
        object.__init__(self)
        self.id = info['id']            # ID string
        self.name = info['name']
        self.mngr  = info['mngr']       # Manager ID string

    def __repr__(self):
        return '%s(name:%s, id:%s, manager:%s)' % (type(self).__name__,
                self.name, self.id, self.mngr)

    def getId(self):
        return self.id

# Tree node class
class TreeNode(object):
    def __init__(self, info={}):
        if info is None:
            self.id = 0
        else:
            self.id = random.randint(1, 0xFFFF)
        #self.idpool = [0, 1]        # Avaliable ids
        self.employeeinfo = EmployeeInfo(info)

    def getContent(self):
        return self.employeeinfo

    def entree(self, root):
        pass

ROOT = TreeNode({'name':'Xuan Wang', 'id':'xuawang', 'mngr':'ranhuang'})

class EEInfoRetriever(HTMLParser):
    """ Parse DIR employ detail page and retrieve ee information
    """

    def handle_starttag(self, tag, attrs):
        print "Encountered the beginning of a %s tag" % tag

    def handle_endtag(self, tag):
        print "Encountered the end of a %s tag" % tag

def geteeinfo():
    url = URL + ROOT.getContent().getId();
    print "Opening URL: %s" % url
    f = urllib.urlopen(url)
    t = f.read()
    #print t
    #return
    retriever = EEInfoRetriever()
    retriever.feed(t)

def main():
    random.seed()

    #node = TreeNode({'name':'Haiyu Zhang', 'id':'haiyuzha', 'mngr':'xuawang'})
    #print node.getContent()

    geteeinfo()

if __name__ == '__main__':
    main()

